package com.weixing.mall.provider.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.enums.IsEnableEnum;
import com.weixing.mall.core.support.auth.AgentAuth;
import com.weixing.mall.provider.api.model.dto.SaleAgentDto;
import com.weixing.mall.provider.api.model.query.AgentInfoQuery;
import com.weixing.mall.provider.api.model.query.AgentMemberQuery;
import com.weixing.mall.provider.api.model.vo.AgentCustomerVo;
import com.weixing.mall.provider.api.model.vo.AgentRpcVo;
import com.weixing.mall.provider.api.model.vo.AgentTreeTableVo;
import com.weixing.mall.provider.api.model.vo.AgentVo;
import com.weixing.mall.provider.model.domain.Agent;
import com.weixing.mall.provider.model.domain.AgentBonusGroup;
import com.weixing.mall.provider.model.dto.AgentBasicEditDto;
import com.weixing.mall.provider.model.query.AgentProfitQuery;
import com.weixing.mall.provider.model.query.AgentQuery;
import com.weixing.mall.provider.model.query.AgentTreeQuery;
import com.weixing.mall.provider.model.query.UpAgentQuery;
import com.weixing.mall.provider.model.vo.*;

import java.util.List;

/**
 * <p>
 * 代理商模块-代理商表 服务类
 * </p>
 *
 * @author Small
 * @since 2019-11-18
 */
public interface IAgentService extends IService<Agent> {

    Long saveBasic(AgentBasicEditDto dto);

    AgentVo selectByMobile(String mobile);

    AgentVo selectByAgentSn(String agentSn);

    AgentVo selectByAgentInfo(AgentInfoQuery agentInfoQuery);


    IPage<AgentTreeVo> structuralTree(Page page, AgentTreeQuery agentStructuralTreeQuery);
    IPage<AgentTreeVo> structuralTree(Page page, AgentTreeQuery agentStructuralTreeQuery, AgentAuth auth);


    List<UpAgentVo> selectByUpAgent(UpAgentQuery upAgentQuery);

    AgentCustomerVo selectByIdAgentCustomer(Long agentId);

    List<AgentVo> selectByParentId(Long agentId);

    AgentVo selectById(Long agentId);

    List<Long> selectByCustomerIdAgentLevel(int parseInt, long currentUserId);

    AgentBasicEditVo selectBasicEditVo(Long id);

    void changeEnable(Long id, IsEnableEnum isEnable);

    IPage<AgentTreeVo> findAgentTreeVoByPId(Page page, Long pid);

    IPage agentMemberAddr(Page initMpPage, AgentMemberQuery agentMemberQuery);

    List<Long> selectAgentIdByAgentLevel(int agentLevel);

    Long[] selectAgentTreeByParentId(Long agentId);

    List<UpAgentVo> selectFormAgent(String agentName);

    List<Agent> findByParentId(Long id);

    Agent findByAgentSn(String agentSn);

    Agent findByMobile(String mobile);

    void agentBind(Agent agent, Agent parent);

    List<Agent> selectLastLevelListByAgentTreeNode(Agent agent, Integer oldLevel);

    Page<AgentProfitVo> profitStatistic(Page initMpPage, AgentProfitQuery agentProfit);

    IPage<AgentTableVo> selectOfPage(Page page, AgentMemberQuery agentMemberQuery);

    List<AgentCustomerVo> selectByCustomerId(Long customerId);

    IPage<AgentVo> selectListOfPage(Page initMpPage, AgentQuery query,boolean forTree);

    Long saveBasicApply(AgentBasicEditDto dto);

    int countGroupPerson(Agent agent);

    List<AgentTreeTableVo> tree(boolean isQueryAll);

    Agent findByWechatNum(String wechatNum);

    IPage<AgentRpcVo> selectChildByAgentId(Page page, long agentId, Integer agentLevel);

    IPage<AgentRpcVo> selectAgentVoByCustomerId(Page page, long kefuId);

    List<Agent> selectObligee(Long kefuId);

    List<AgentVo> selectBonusAgent(Long agentId);

    List<Agent> selectObligeeChild(Long agentId);

    void delAgent(Long id);

    List<Agent> listAll();

    List<Agent> listAllByKefuId(Long uid);

    List<Agent> listAllByAgentIdAndAgentLevel(long agentId, Integer agentLevel);

    void expireTask();

    List<AgentTreeTableVo> treeForAgent(Long agentId);

    List<Agent> selectObligor(Long kefuId);

    int countKefuGroupCnt(Long id);

    void resetPwd(Agent byId, String newPwd);

    IPage<AgentVo> selectListOfPageForAgent(Page initMpPage, AgentQuery query, boolean b);

    List<AgentBonusGroup> selectObligeeOwn(Long agentId);


    int countTotalByIsEnable(Integer value);

    int countExpTotal();

    int countTotalByIsOfficial(Integer value);

    List<String> loadKefuMasterCid();

    /**
     * 加入/移除 黑名单
     *
     * @param agentId   代理商id
     * @param blackFlag 黑名单标识
     */
    Result pullOrDetachBlack(Long agentId,Integer blackFlag);

    /**
     * 统计代理团队人数
     *
     * @param agentId  代理商id
     * @param agentLevel  代理商等级
     * @return  团队人数
     */
    int countAgentGroupCnt(Long agentId, Integer agentLevel);

    IPage<AgentRpcVo> selectChildByAgent(Page initMpPage, SaleAgentDto dto, Integer agentLevel);

    /**
     * 查询全部有效代理
     *
     * @return  代理
     */
    List<Agent> selectEnableAll();

    List<AgentTreeVo> getTop10AgentTeam();
}
